<?php
/*
	$Id: tankspot.php 9 2007-09-21 19:01:10Z davoro $
	
	Shows shield block value parsed from Wow armory profile
	
	Based on formula:
	blockValue = floor(blockValueFromStrength) + floor((blockValueFromItems + blockValueFromShield) * blockValueMod)
	
	Author: davoro@gmail.com
*/
include_once('_armory.php');
include_once('_functions.php');

define('ARMORY_PATH', 'wowarmory.com');
define('CHAR_NAME', 'Deda');
define('SERVER_NAME', 'Thrall');

/*
	Shield Mastery	Rank 1/2/3
	Increases the amount of damage absorbed by your shield by 10%/20%/30%.
*/
$shield_mastery = array(0=>1, 1=>1.1, 2=>1.2, 3=>1.3);
$block_value_pattern = '/^Increases the block value of your shield by ([^ ]+).$/';
$block = 0;
$str_to_block = 0;

$charData = getCharacterData('http://' . ARMORY_PATH, SERVER_NAME, CHAR_NAME);
$strength = $charData->xpath("/page/characterInfo/characterTab/baseStats/strength");
$att = attribs($strength[0]);
$str_to_block = $att['block'];

$items = $charData->xpath("/page/characterInfo/characterTab/items/item");
foreach($items as $t) {
	$att = attribs($t);
	$itemData = getItemData('http://' . ARMORY_PATH, $att['id']);
	$item = $itemData->xpath("/page/itemTooltips/itemTooltip/spellData/spell/desc");

	if(isset($item[0]) && preg_match($block_value_pattern, $item[0], $matches)) {
		$block += $matches[1];
	}
	// add base shield block value
	if($att['slot']==16) {
		$shield_block_base = $itemData->xpath("/page/itemTooltips/itemTooltip/blockValue");
		if(isset($shield_block_base[0])) { 
			$block += $shield_block_base[0];
		}
	}	
}
// shield mastery talent
$talentData = getTalentData('http://' . ARMORY_PATH, SERVER_NAME, CHAR_NAME);
$talentTree = $talentData->xpath("/page/characterInfo/talentTab/talentTree");
$talentTree_att = attribs($talentTree[0]);
$build = $talentTree_att['value'];
$sm_points = substr($build , -7, 1);

$block = floor($block * $shield_mastery[$sm_points]);
$block += $str_to_block;

echo $block;

?>
